package com.basis.message;

import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

import jxl.common.Logger;

public class MessageUtils extends JSONObject{

	private Logger logger = Logger.getLogger(this.getClass());
	
	public MessageUtils(){
		try {
			JSONObject errorMessage = new JSONObject();
			this.put("message", errorMessage);
			this.put("retryExecution", true);
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
	
	public void setError(String text){
		try {
			JSONObject errorMessage  = this.getJSONObject("message");
			errorMessage.put("severity", "error");
			errorMessage.put("text", text);
		} catch (JSONException e) {
			logger.error(e);
		}
	}
	
	public void setSuccess(String text){
		try {
			JSONObject errorMessage  = this.getJSONObject("message");
			errorMessage.put("severity", "success");
			errorMessage.put("text", text);
		} catch (JSONException e) {
			logger.error(e);
		}
	}
	
	public void setSuccess(){
		this.setSuccess("");
	}

}
